package com.example.Activity.controller;

import com.example.Activity.domain.Bo.ActivityRegistrationAddBo;
import com.example.Activity.domain.Vo.ActivityRegistrationListVo;
import com.example.Activity.service.IActivityRegistrationService;
import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/activityRegistration")
@Api(value = "/activityRegistration", tags = "活动报名管理")
public class ActivityRegistrationController {

    @Autowired
    private IActivityRegistrationService activityRegistrationService;

    @GetMapping("/list")
    @ApiOperation("获取报名列表")
    public R<List<ActivityRegistrationListVo>> getActivityRegistrationList(ActivityRegistrationAddBo bo) {
        LoginUser loginUser = UserUtil.getLoginUser();
        bo.setUserId(loginUser.getUserId());
        List<ActivityRegistrationListVo> list = activityRegistrationService.selectActivityRegistration(bo);
        return R.success(list);
    }

    @GetMapping("/myRegistrations")
    @ApiOperation("获取我的报名列表")
    public R<List<ActivityRegistrationListVo>> getMyRegistrations() {
        LoginUser loginUser = UserUtil.getLoginUser();
        ActivityRegistrationAddBo bo = new ActivityRegistrationAddBo();
        bo.setUserId(loginUser.getUserId());
        List<ActivityRegistrationListVo> list = activityRegistrationService.selectActivityRegistration(bo);
        return R.success(list);
    }

    @PostMapping("/add")
    @ApiOperation("新增报名")
    public R<ActivityRegistrationAddBo> addActivityRegistration(@RequestBody ActivityRegistrationAddBo bo) {
        LoginUser loginUser = UserUtil.getLoginUser();
        bo.setUserId(loginUser.getUserId());
        activityRegistrationService.insertActivityRegistration(bo);
        return R.success(bo);
    }

    @PostMapping("/update")
    @ApiOperation("修改报名状态")
    public R updateActivityRegistrationById(@RequestBody ActivityRegistrationAddBo bo) {
        LoginUser loginUser = UserUtil.getLoginUser();
        bo.setUserId(loginUser.getUserId());
        activityRegistrationService.updateActivityRegistrationById(bo);
        return R.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除报名")
    public R deleteActivityRegistrationById(@PathVariable String id) {
        activityRegistrationService.deleteActivityRegistrationById(id);
        return R.success();
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("获取报名详情")
    public R<ActivityRegistrationListVo> getRegistrationDetail(@PathVariable Integer id) {
        ActivityRegistrationListVo registration = activityRegistrationService.selectActivityRegistrationById(id);
        return R.success(registration);
    }
}